home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 466_01 / SRC / INPUT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-20  |  1.9 KB  |  100 lines

  1. #include <afx.h>
  2. #include <afxtempl.h>
  3. #include "input.h"
  4. #include "errmsg.h"
  5. #include "parse.h"
  6.  
  7. /**************************************************************************/
  8.  
  9. //@doc FILE ADINPUT
  10.  
  11. //@mfunc Constructs the input file object, zeroes the line
  12. // buffer.
  13.  
  14. CAdInput::CAdInput(void)
  15. {
  16.     ZeroMem(&m_szLineBuf, MAXLINEBUFSIZE+1);
  17.     m_lCurLine     = 0;
  18.     m_nAdState.Reuse = FALSE;
  19.     m_nAdState.Append = FALSE;
  20.     m_nAdState.EndOfFile = FALSE;
  21. }
  22.  
  23.  
  24.  
  25.  
  26. /***********************************************************/
  27. // Input operations
  28. /***********************************************************/
  29.  
  30. //@mfunc Gets a line from the input file and stores it in
  31. // <md .m_szLineBuf>. If the Reuse state is set in <md .m_nAdState>
  32. // the function simply returns without refreshing the buffer.
  33. //
  34. //@rdesc Zero or a file exception error from <c CFileException>.
  35.  
  36. int CAdInput::GetLine(void)
  37. {
  38. TRY
  39. {
  40.     ASSERT(m_hFile != NULL);
  41.     char *sz;
  42.     int  n;
  43.  
  44.     if(m_nAdState.Reuse)
  45.     {
  46.         m_nAdState.Reuse = FALSE;
  47.         return 0;
  48.     }
  49.  
  50.     if(m_nAdState.Append)
  51.     {
  52.         m_nAdState.Append = FALSE;
  53.  
  54.         n = strlen(m_szLineBuf);
  55.  
  56.         // If there was a carriage return at end, overwrite it -
  57.         // will treat this entire series as a single line for
  58.         // easier parsing later.
  59.  
  60.         if(n >= 2 && m_szLineBuf[n-1] == '\n')
  61.         {
  62.             n--;
  63.             m_szLineBuf[n-1] = chSpace;
  64.         }
  65.  
  66.         if(MAXLINEBUFSIZE - n <= 0) 
  67.             return errMultilineOverflow;
  68.  
  69.         sz = m_szLineBuf + n;
  70.     }
  71.     else
  72.     {
  73.         ZeroMem(m_szLineBuf, MAXLINEBUFSIZE+1);
  74.  
  75.         n = 0;
  76.         sz = m_szLineBuf;
  77.     }
  78.  
  79.     if(ReadString(sz, MAXLINEBUFSIZE - n) == NULL)
  80.         m_nAdState.EndOfFile = TRUE;
  81.     
  82.     m_lCurLine++;
  83.         
  84.     return 0;
  85. }
  86. CATCH(CFileException, e)
  87. {
  88.     return e->m_cause;
  89. }
  90. END_CATCH
  91. }
  92.  
  93.  
  94. //@mfunc Resets the <md .m_nAdState> variable.
  95.  
  96. void CAdInput::ResetState(void)
  97. {
  98.     ZeroMem(&m_nAdState, sizeof(m_nAdState)); 
  99. }
  100.